package com.jh.fcsm.common;

import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.fastjson2.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.jh.fcsm.common.annotation.FieldTypeAnnotation;
import com.jh.fcsm.util.CamelCaseToSnakeCase;
import com.jh.fcsm.util.txt.StringUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.apache.ibatis.type.JdbcType;
import tk.mybatis.mapper.annotation.ColumnType;

import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Transient;
import java.io.Serializable;
import java.util.Date;

/**
 * 类描述:实体基类
 *
 * @author szx
 * @date 2017年5月4日
 */
@ApiModel(value = "com.jh.fcsm.common", description = "实体基类")
public class BaseEntity implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 主键
     */

    @FieldTypeAnnotation(getName = "ID")
    @Id
    @ApiModelProperty(value = "主键")
    private String id;

    @Column(name = "CREATE_TIME")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    @JSONField(format = "yyyy-mm-dd HH:mm:ss")
    @ApiModelProperty(value = "创建时间")
    private Date createTime;

    @Column(name = "UPDATE_TIME")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    @JSONField(format = "yyyy-mm-dd HH:mm:ss")
    @ApiModelProperty(value = "更新时间")
    private Date updateTime;

    @Column(name = "CREATE_USER")
    @ApiModelProperty(value = "创建用户ID")
    @ColumnType(jdbcType = JdbcType.VARCHAR)
    private String createUser;

    @Column(name = "CREATE_USER_NICKNAME")
    @ApiModelProperty(value = "创建用户名称")
    private String createUserNickname;

    @Column(name = "UPDATE_USER")
    @ApiModelProperty(value = "更新用户")
    private String updateUser;

    @Column(name = "UPDATE_USER_NICKNAME")
    @ApiModelProperty(value = "更新用户名称")
    private String updateUserNickname;

    @JsonIgnore
    @Column(name = "ATTR1")
    @ApiModelProperty(value = "备用字段1")
    private String attr1;
    @JsonIgnore
    @Column(name = "ATTR2")
    @ApiModelProperty(value = "备用字段2")
    private String attr2;
    @JsonIgnore
    @Column(name = "ATTR3")
    @ApiModelProperty(value = "备用字段3")
    private String attr3;
    @JsonIgnore
    @Column(name = "ATTR4")
    @ApiModelProperty(value = "备用字段4")
    private String attr4;
    @JsonIgnore
    @Column(name = "ATTR5")
    @ApiModelProperty(value = "备用字段5")
    private String attr5;
    @JsonIgnore
    @ApiModelProperty(value = "是否生效 1：是 0：否")
    private Integer yn;
    @ApiModelProperty(value = "排序字段(下划线)")
    @Transient
    private String orderColumn;

    @ApiModelProperty(value = "排序字段属性")
    @Transient
    private String orderProp;


    @ApiModelProperty(value = "排序 desc asc")
    @Transient
    private String orderValue;

    public String getOrderProp() {
        return orderProp;
    }

    public void setOrderProp(String orderProp) {
        this.orderProp = orderProp;
    }

    public String getOrderColumn() {
        if (StringUtils.isEmpty(orderProp)) {
            return "UPDATE_TIME";
        }
        return CamelCaseToSnakeCase.camelCaseToSnakeCase(orderProp);


    }

    public void setOrderColumn(String orderColumn) {
        this.orderColumn = orderColumn;
    }

    public String getOrderValue() {
        if (StringUtils.isEmpty(orderValue)) {
            return "desc";
        } else {
            if (orderValue.equals("descending")) {
                orderValue = "desc";
            } else {
                orderValue = "asc";
            }
        }
        return orderValue;
    }

    public void setOrderValue(String orderValue) {
        this.orderValue = orderValue;
    }
    public Date getCreateTime() {
        if (createTime != null) {
            return new Date(createTime.getTime());
        }
        return null;
    }

    public void setCreateTime(Date createTime) {
        if (createTime != null) {
            this.createTime = new Date(createTime.getTime());
        }
    }

    public Date getUpdateTime() {
        if (updateTime != null) {
            return new Date(updateTime.getTime());
        }
        return null;
    }

    public void setUpdateTime(Date updateTime) {
        if (updateTime != null) {
            this.updateTime = new Date(updateTime.getTime());
        }
    }

    public Integer getYn() {
        return yn;
    }

    public void setYn(Integer yn) {
        this.yn = yn;
    }

    /**
     * 获取主键
     *
     * @return id - 主键
     */
    public String getId() {
        return id;
    }

    /**
     * 设置主键
     *
     * @param id 主键
     */
    public void setId(String id) {
        this.id = id == null ? null : id.trim();
    }

    public String getCreateUser() {
        return createUser;
    }

    public void setCreateUser(String createUser) {
        this.createUser = createUser;
    }

    public String getUpdateUser() {
        return updateUser;
    }

    public void setUpdateUser(String updateUser) {
        this.updateUser = updateUser;
    }

    public String getAttr1() {
        return attr1;
    }

    public void setAttr1(String attr1) {
        this.attr1 = attr1;
    }

    public String getAttr2() {
        return attr2;
    }

    public void setAttr2(String attr2) {
        this.attr2 = attr2;
    }

    public String getAttr3() {
        return attr3;
    }

    public void setAttr3(String attr3) {
        this.attr3 = attr3;
    }

    public String getAttr4() {
        return attr4;
    }

    public void setAttr4(String attr4) {
        this.attr4 = attr4;
    }

    public String getAttr5() {
        return attr5;
    }

    public void setAttr5(String attr5) {
        this.attr5 = attr5;
    }

    public String getCreateUserNickname() {
        return createUserNickname;
    }

    public void setCreateUserNickname(String createUserNickname) {
        this.createUserNickname = createUserNickname;
    }

    public String getUpdateUserNickname() {
        return updateUserNickname;
    }

    public void setUpdateUserNickname(String updateUserNickname) {
        this.updateUserNickname = updateUserNickname;
    }
}
